package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.skynet.vpn.free.view.ConnectView
import kotlinx.coroutines.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val connectView = findViewById<ConnectView>(R.id.connectView)
        connectView.setOnClickListener {
            MainScope().launch {
                withContext(Dispatchers.Main) {
                    connectView.startConnecting()
                    withContext(Dispatchers.IO) {
                        delay(4 * 1000L)
                    }
                    connectView.setConnected()
                    /* withContext(Dispatchers.IO) {
                         delay(4 * 1000L)
                     }
                     findViewById<ConnectView>(R.id.connectView).setDisConnecting()*/
                }
            }
        }

        findViewById<Button>(R.id.reset).setOnClickListener {
            connectView.reset()
        }
        findViewById<Button>(R.id.connectIng).setOnClickListener {
            connectView.startConnecting()
        }

        findViewById<Button>(R.id.Connected).setOnClickListener {
            connectView.setConnected()
        }

        findViewById<Button>(R.id.DisConnected).setOnClickListener {
            connectView.setDisConnecting()
        }
    }
}